package net.dianpin;

import net.dianpin.dao.generate.CompanyMapper;
import net.dianpin.model.generate.Company;
import net.dianpin.model.generate.CompanyExample;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * Created by lei on 2014/6/2.
 */
public class Test {
    private static Logger logger = Logger.getLogger(Test.class);
    public static void main(String[] args) {
        ApplicationContext applicationContext =
                new ClassPathXmlApplicationContext("application_context.xml");
//
//        UserMapper userMapper = applicationContext.getBean(UserMapper.class);
//        System.out.println(userMapper);
//        List<User> userList = userMapper.getAllUser();
//        System.out.println(userList.size());

        SqlSessionFactory sqlSessionFactory = applicationContext.getBean("sqlSessionFactory",SqlSessionFactory.class);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        logger.info("Get sqlSession successfully...");

//        CompanyMapper companyMapper = sqlSession.getMapper(CompanyMapper.class);
//
//        Company company = new Company();
//        company.setCompanyName("中国银行");
//        company.setPassword("123456");
//        company.setTelephone("15658153613");
//        company.setEmail("lo2007@126.com");
//        company.setAddress("杭州西湖区");
//        company.setBusinessLicense("23232323232");
//        company.setState(0);
//
//        companyMapper.insert(company);
//        CompanyExample companyExample = new CompanyExample();
//        CompanyExample.Criteria criteria = companyExample.createCriteria();
//        criteria.andCompanyIdGreaterThan(0);
//
//        List<Company> companyList = companyMapper.selectByExample(companyExample);
//        System.out.println(companyList.size());
//        sqlSession.commit();
//        sqlSession.close();
    }
}
